using System;
using System.Data;
using System.Data.SqlClient;
using System.Data.SqlTypes;
using Microsoft.SqlServer.Server;

public partial class StoredProcedures
{
    [Microsoft.SqlServer.Server.SqlProcedure]
    public static void JobOutputCleanup(SqlInt32 p_fileRetentionInDays)
    {
        using (SqlConnection sqlConnection = new SqlConnection("Context connection = true"))
        {
            sqlConnection.Open();
            using (SqlCommand sqlCommand = new SqlCommand())
            {
                sqlCommand.Connection = sqlConnection;
                sqlCommand.CommandText = "EXEC [maint].[GetJobOutputPaths]";
                SqlDataReader sqlDataReader = sqlCommand.ExecuteReader();
                while (sqlDataReader.Read())
                    StoredProcedures.DeleteJobFiles(sqlDataReader["FilePath"].ToString(), (int)p_fileRetentionInDays);
                sqlDataReader.Close();
            }
        }
    }
}
